/**
 * 字典下拉组件
 */
import { Select } from 'ant-design-vue'

export default {
  name: 'DictSelect',
  props: {
    value: [String, Number, Array],
    lxjp: String,
    isCache: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {}
  },
  computed: {
    dicts () {
      if (!this.lxjp) return []
      const opts = this.$store.state.dict[this.lxjp] || []
      return opts
    }
  },
  mounted () {
    const { lxjp, isCache } = this
    if (lxjp) {
      this.$store.dispatch('dict/fetchDict', { lxjp, isCache })
    }
  },
  render () {
    return (
      <Select
        props={{
          value: this.value,
          options: this.dicts,
          ...this.$attrs
        }}
        on={{
          change: value => this.$emit('change', value),
          ...this.$listeners
        }} />
    )
  }
}
